<?php
namespace App\Server;


use App\Exceptions\UploadException;
use Houdunwang\LaravelUpload\Events\UploadEvent;

class UploadServer{
    public function upload($file,$type){
        $this->check($file,$type);
        $event=new UploadEvent($file);
        event($event);
        return $event->getFile();
    }

    protected function check($file,$type){
        if($file->getSize()>hd_config('upload.'.$type.'_size')){
            throw new UploadException('上传文件过大');
        }
        $ext = strtolower ( $file->getClientOriginalExtension () );
        if(!in_array ($ext,explode (',',hd_config('upload.'.$type.'_type')))){
            throw  new UploadException('上传类型不允许');
        }
    }
}